"use client";
import React, { useEffect, useLayoutEffect, useState } from "react";
import "./info.css";
import { getNewsById } from "@/app/api";
import parse from 'html-react-parser';
import { title } from "process";
export default function Info({ params }:{params:{id:string}}) {
  const [news, setNews] = useState({
    id:"",
    title:"",
    writer:"",
    createTime:"",
    content:"",
  });
  useLayoutEffect(() => {
    window.scrollTo(0, 0);
    getNewsById(params.id).then((res) => {
      setNews(res.data);
     
    });
  }, []);

  return (
    <div className="content">
      <div className="content_area">
        <div className="news_content">
          <div className="news_content_header">
            <div className="news_title">{news.title}</div>
            <div className="news_info">
              <span>作者：{news.writer}</span>
              <span
                style={{
                  marginLeft: "20px",
                }}
              >
                发布时间：{news.createTime}
              </span>
            </div>
          </div>
          <div
            className="news_page_content"
          >{parse(news?.content ?? '')}</div> 
        </div>
      </div>
    </div>
  );
}
